<template>
    <!--课程直播录播页-->
    <div class="contain">
        <iframe id="live" class="live" :src="videoSrc" allowfullscreen="true" allowtransparency="true">

        </iframe>
    </div>
</template>
<script>
    import aesUtil from '../../plugins/common/aesUtil';
    export default {
        name: 'live',
        components: {
            /**/
        },
        data() {
            return {
                account: '',
                height: null,
                videoSrc: '',
                channelid: '',
                logId: null
            };
        },
        computed: {
        },
        watch: {
            /**/
        },
        mounted() {
            window.aesUtil = aesUtil;
            let id = decodeURI(this.$route.query.id);
            this.channelid = this.$route.query.channelId;
            if(this.channelid) {

            }else if(id) {
                this.channelid = aesUtil.decrypt(id);
            }
            this.videoLogInit();
            window.onbeforeunload = ()=>{
                this.videoLogEnd()
            }
            window.addEventListener('beforeunload', ()=> {
                this.videoLogEnd()
            })
            this.videoSrc = 'https://live.polyv.cn/watch/' + this.channelid;
            let tag
            if(document.getElementsByTagName('iframe')) {
                tag = document.getElementsByTagName('iframe')[0].contentWindow
            }
            this.height = tag.document.body.scrollHeight + 300
            return tag
        },
        destroy(){
            this.videoLogEnd();
        },
        methods: {
            videoLogInit(){
                let option = {
                    pathName: 'saveSplog',
                    authorization: true,
                    params: {
                        spid: this.channelid,
                        type: this.$route.query.type,
                    }
                };
                this.$api.ajaxData(option)
                    .then(res => {
                        this.logId = res.obj.id
                    });
            },
            videoLogEnd(){
                if(!this.logId) return;
                let option = {
                    pathName: 'saveSplog',
                    authorization: true,
                    params: {
                        spid: this.channelid,
                        type: this.$route.query.type,
                        id: this.logId
                    }
                };
                this.$api.ajaxData(option)
                    .then(() => {
                    });
            }
        }
    };
</script>
<style scoped lang="scss">
.contain {
    position: absolute;
    width: 100%;
    left: 0;
.live {
    position: relative;
    width: 100%;
    height: calc(100vh - 80px);
    border: none;
    &>*::-webkit-scrollbar {
        display: none;
    }
}
}
</style>
